package com.github.postsanf.yinian.activity;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.RotateAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.github.postsanf.yinian.BaseActivity;
import com.github.postsanf.yinian.R;
import com.github.postsanf.yinian.adapter.MembersHorizontalTopAdapter;
import com.github.postsanf.yinian.adapter.TimeLineStatusFristAdapter;
import com.github.postsanf.yinian.bean.YNAlbum;
import com.github.postsanf.yinian.bean.YNReward;
import com.github.postsanf.yinian.bean.YNStatus;
import com.github.postsanf.yinian.constants.ACTIONs;
import com.github.postsanf.yinian.constants.CommonConstants;
import com.github.postsanf.yinian.constants.YNSingleton;
import com.github.postsanf.yinian.entity.YNRewardResponse;
import com.github.postsanf.yinian.entity.YNStatusResponse;
import com.github.postsanf.yinian.fragment.MineFragement;
import com.github.postsanf.yinian.utils.DisplayUtils;
import com.github.postsanf.yinian.utils.ReqUtils;
import com.github.postsanf.yinian.utils.SpUtils;
import com.github.postsanf.yinian.utils.UIHelper;
import com.github.postsanf.yinian.utils.YNInviteSecret;
import com.github.postsanf.yinian.widget.AutoPollRecyclerView;
import com.github.postsanf.yinian.widget.FeedRootRecyclerView;
import com.github.postsanf.yinian.ynlist.LoadingFooter;
import com.github.postsanf.yinian.ynlist.RecyclerViewStateUtils;
import com.litesuits.http.exception.HttpException;
import com.litesuits.http.listener.HttpListener;
import com.litesuits.http.request.StringRequest;
import com.litesuits.http.request.param.HttpMethods;
import com.litesuits.http.response.Response;

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import sweetcamera.CameraActivity;

public class TimeLineStatusFristActivity extends BaseActivity implements View.OnClickListener, SwipeRefreshLayout.OnRefreshListener {
    private FeedRootRecyclerView mRecyclerView;
    private SwipeRefreshLayout mRefreshlayout;
    private TimeLineStatusFristAdapter mTimeLineStatusAdapter;
    private List<YNStatus> groupStatusItems = new ArrayList<>();
    private boolean isBottom = false;
    private boolean refresh = false;
    private TextView peoplespace_title;
    private ImageView peoplespace_search;
    private AutoPollRecyclerView members_recycler_horizontal;
    private MembersHorizontalTopAdapter mAdapter;
    private List<YNReward> mRewardDatas = new ArrayList<>();
    private YNAlbum curAlbum;
    private RelativeLayout status;
    private RelativeLayout status_empty;
    public static HashMap<Integer, String> rewardtips = new HashMap<>();
    public static String ShareTitle = "";
    public static String ShareContent = "";
    private RelativeLayout ll_buttons, ll_buttons_ll;
    private ImageView buttons_cover;
    private ImageView btn_middle_selector_copy;
    private ImageView tabiv2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_timeline_topstatus);
        registerBroadcastReceiver();
        rewardtips.put(8, "礼品");
        rewardtips.put(28, "礼品");
        rewardtips.put(48, "礼品");
        rewardtips.put(68, "礼品");
        curAlbum = (YNAlbum) getIntent().getSerializableExtra("StatusFrist");
        ShareTitle = curAlbum.getShareTitle();
        ShareContent = curAlbum.getShareContent();
        initView();
    }

    private void initView() {
        findViewById(R.id.top_back).setOnClickListener(this);
        findViewById(R.id.top_back_time).setOnClickListener(this);
        findViewById(R.id.btn_space_huodong).setOnClickListener(this);
        tabiv2 = (ImageView) findViewById(R.id.btn_middle_selector);
        tabiv2.setOnClickListener(this);
        findViewById(R.id.btn_space_paihangbang).setOnClickListener(this);

        ll_buttons = (RelativeLayout) findViewById(R.id.ll_buttons);
        ll_buttons_ll = (RelativeLayout) findViewById(R.id.ll_buttons_ll);
        btn_middle_selector_copy = (ImageView) findViewById(R.id.btn_middle_selector_copy);
        buttons_cover = (ImageView) findViewById(R.id.buttons_cover);
        buttons_cover.setClickable(true);
        buttons_cover.setOnClickListener(this);
        findViewById(R.id.tv_image).setOnClickListener(this);
        findViewById(R.id.tv_pailide).setOnClickListener(this);
        status = (RelativeLayout) this.findViewById(R.id.status);
        status_empty = (RelativeLayout) this.findViewById(R.id.status_empty);
        peoplespace_title = (TextView) this.findViewById(R.id.peoplespace_title);
        peoplespace_search = (ImageView) this.findViewById(R.id.peoplespace_search);
        peoplespace_search.setOnClickListener(this);
        members_recycler_horizontal = (AutoPollRecyclerView) this.findViewById(R.id.members_recycler_horizontal);
        members_recycler_horizontal.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
        mRecyclerView = (FeedRootRecyclerView) this.findViewById(R.id.album_status_recyclerview);
        mRefreshlayout = (SwipeRefreshLayout) this.findViewById(R.id.album_status_swipe_refresh);
        mRefreshlayout.setColorSchemeColors(getResources().getColor(R.color.yncolor));
        mRefreshlayout.setOnRefreshListener(this);
        mRefreshlayout.post(new Runnable() {
            @Override
            public void run() {
                mRefreshlayout.setRefreshing(true);
            }
        });
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
                int visibleItemCount = layoutManager.getChildCount();
                int totalItemCount = layoutManager.getItemCount();
                if ((visibleItemCount > 0 && newState == RecyclerView.SCROLL_STATE_IDLE && (((LinearLayoutManager) layoutManager).findLastVisibleItemPosition()) >= totalItemCount - 1)) {
                    if (isBottom) {
                        return;
                    }
                    LoadingFooter.State state = RecyclerViewStateUtils.getFooterViewState(mRecyclerView);
                    if (state == LoadingFooter.State.Loading) {
                        return;
                    }
                    RecyclerViewStateUtils.setFooterViewState(TimeLineStatusFristActivity.this, mRecyclerView, 10, LoadingFooter.State.Loading, null);
                    mRecyclerView.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            loadStatus(false);
                        }
                    }, 600);
                }
            }
        });
        noticeRewardsServiceInit();
        noticePaihangServiceInit();
        if (curAlbum != null && curAlbum.getGnum() != null) {
            peoplespace_title.setText(curAlbum.getGname());
        }
        groupStatusItems.clear();
        mTimeLineStatusAdapter = new TimeLineStatusFristAdapter(TimeLineStatusFristActivity.this, groupStatusItems, application.getCurID(), true);
        mRecyclerView.setAdapter(mTimeLineStatusAdapter);
        noticeServiceInit();
    }


    boolean btnAnimation = false;

    private void OpenButtons() {
        if (btnAnimation) {
            return;
        }
        btnAnimation = true;
        btn_middle_selector_copy.setVisibility(View.VISIBLE);
        RotateAnimation rotateAnimationtab = new RotateAnimation(0, -135f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        Animation translateAnimationtab = new TranslateAnimation(0, 0, UIHelper.dip2px(TimeLineStatusFristActivity.this, 5), 0);
        AnimationSet animationSettab = new AnimationSet(true);
        animationSettab.addAnimation(rotateAnimationtab);
        animationSettab.addAnimation(translateAnimationtab);
        animationSettab.setFillAfter(true);
        animationSettab.setDuration(500);
        animationSettab.setInterpolator(new DecelerateInterpolator());
        tabiv2.setVisibility(View.GONE);
        btn_middle_selector_copy.startAnimation(animationSettab);
        Animation translateAnimationbtns = new TranslateAnimation(0, 0, UIHelper.dip2px(TimeLineStatusFristActivity.this, 120), 0);
        AlphaAnimation alphaAnimationbtns = new AlphaAnimation(0.0f, 1.0f);
        AnimationSet animationSetbtns = new AnimationSet(true);
        animationSetbtns.addAnimation(translateAnimationbtns);
        animationSetbtns.addAnimation(alphaAnimationbtns);
        animationSetbtns.setDuration(500);
        ll_buttons_ll.startAnimation(animationSetbtns);
        ll_buttons.setVisibility(View.VISIBLE);
        AlphaAnimation alphaAnimationcover = new AlphaAnimation(0.0f, 1.0f);
        alphaAnimationcover.setDuration(800);
        buttons_cover.startAnimation(alphaAnimationcover);
        buttons_cover.setVisibility(View.VISIBLE);
    }

    private void CloseButtons() {
        if (!btnAnimation) {
            return;
        }
        btnAnimation = false;
        btn_middle_selector_copy.setVisibility(View.GONE);
        ll_buttons.setVisibility(View.GONE);
        tabiv2.setVisibility(View.VISIBLE);
        Animation translateAnimationbtns = new TranslateAnimation(0, 0, 0, UIHelper.dip2px(TimeLineStatusFristActivity.this, 120));
        AlphaAnimation alphaAnimationbtns = new AlphaAnimation(1.0f, 0.0f);
        AnimationSet animationSetbtns = new AnimationSet(true);
        animationSetbtns.addAnimation(translateAnimationbtns);
        animationSetbtns.addAnimation(alphaAnimationbtns);
        animationSetbtns.setDuration(500);
        ll_buttons_ll.startAnimation(animationSetbtns);
        AlphaAnimation alphaAnimationcover = new AlphaAnimation(1.0f, 0.0f);
        alphaAnimationcover.setDuration(800);
        buttons_cover.startAnimation(alphaAnimationcover);
        alphaAnimationcover.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                buttons_cover.setVisibility(View.GONE);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }
        });

    }

    @Override
    public void onRefresh() {
        System.gc();
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                noticeServiceInit();
            }
        }, 500);
    }

    private void updateView(boolean isTop, List<YNStatus> StatusList) {
        mRefreshlayout.setRefreshing(false);
        if (isTop) {
            //此处为活动相册下拉刷新必须加载方法，防止下拉刷新重复
            mTimeLineStatusAdapter.addItemsFromTop(null);
            mTimeLineStatusAdapter.addItemsFromTop(StatusList);
            mRecyclerView.scrollToPosition(0);
        } else {
            mTimeLineStatusAdapter.addItemsFromBottom(StatusList);
            if (StatusList.size() == 0) {
                isBottom = true;
                RecyclerViewStateUtils.setFooterViewState(this, mRecyclerView, 10, LoadingFooter.State.TheEnd, null);
            } else {
                RecyclerViewStateUtils.setFooterViewState(mRecyclerView, LoadingFooter.State.Normal);
            }
        }
        if (refresh) {
            mTimeLineStatusAdapter.notifyDataSetChanged();
            refresh = false;
        }
    }

    private void loadStatus(boolean isTop) {
        isBottom = false;
        int loadId = mTimeLineStatusAdapter.getIdByDirection(isTop);
        LinkedHashMap<String, String> mParam = new LinkedHashMap<>();
        mParam.put(CommonConstants.YNS_USER_ID, String.valueOf(application.getCurID()));
        mParam.put(CommonConstants.YNS_GROUP_ID, String.valueOf(curAlbum.getGroupid()));
        mParam.put(CommonConstants.YNS_EID, String.valueOf(loadId));
        if (loadId != 0) {
            mParam.put(CommonConstants.YNS_TYPE, "loading");
        } else {
            mParam.put(CommonConstants.YNS_TYPE, "initialize");
        }
        StringRequest req = new StringRequest("https://api.zhuiyinanian.com/YinianProject/event/ShowTimeAxis")
                .setMethod(HttpMethods.Post)
                .setParamMap(mParam)
                .setHttpListener(new HttpListener<String>(true, false, true) {
                    @Override
                    public void onSuccess(String s, Response<String> response) {
//                        Log.i("xjs", "frist=====ssss==>" + s);
                        YNStatusResponse resAlbumStatus = gson.fromJson(s, YNStatusResponse.class);
                        if (resAlbumStatus != null && ReqUtils.isSuccess(resAlbumStatus.getCode())) {
                            updateView(false, resAlbumStatus.getData());
                        }
                    }

                    @Override
                    public void onFailure(HttpException e, Response<String> response) {
//                        showToast(CommonConstants.YN_NET_LINK);
                    }
                });
        liteHttp.executeAsync(req);
    }


    BroadcastReceiver mStatusBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            switch (action) {
                case "doReward":
                    int userid = intent.getIntExtra("userid", 0);
                    int type = intent.getIntExtra("type", 0);
                    Iterator iter = rewardtips.entrySet().iterator();
                    while (iter.hasNext()) {
                        Map.Entry entry = (Map.Entry) iter.next();
                        int key = (Integer) entry.getKey();
                        if (key == type) {
                            doReward(userid, type);
                        }
                    }
                    break;
                case "doClickFristShare":
                    YNStatus ynStatus = (YNStatus) intent.getSerializableExtra("ynStatus");
                    String url = "http://wx.zhuiyinanian.com/app/shareactivitydetail.html?code=";
                    String sec = null;
                    try {
                        sec = YNInviteSecret.encryptDES("eid=" + ynStatus.getEid(), getResources().getString(R.string.UNKNOW_ID));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    url = url + sec;
                    Intent sintent = new Intent(TimeLineStatusFristActivity.this, LineTimeStatusFristShareActivity.class);
                    sintent.putExtra("UrlShare", url);
                    sintent.putExtra("title", ShareTitle);
                    sintent.putExtra("desc", ShareContent);
                    sintent.putExtra("avatarPaths", MineFragement.avatarPic);
                    startActivity(sintent);
                    break;
                case ACTIONs.actionUpdateEmptyAlbum:
                    status.setVisibility(View.GONE);
                    status_empty.setVisibility(View.VISIBLE);
                    break;
                case ACTIONs.actionComment:
                    mTimeLineStatusAdapter.SyncComment();
                    break;
                case ACTIONs.actionLike:
                    mTimeLineStatusAdapter.SyncLike();
                    break;
                case ACTIONs.actionStatus:
                    boolean isAdd = intent.getExtras().getBoolean(ACTIONs.IsAdd);
                    int statusID = intent.getExtras().getInt(ACTIONs.StatusId);
                    doSyncStatus(isAdd, statusID);
                    break;
                case ACTIONs.actionSinglePhoto:
//                    String PhotoUrl = intent.getStringExtra(ACTIONs.PhotoUrl);
//                    for (int i = 0; i < groupStatusItems.size(); i++) {
//                        if (PhotoUrl != null && PhotoUrl.equals(groupStatusItems.get(i).getUrl())) {
//                            groupStatusItems.remove(i);
//                            mTimeLineStatusAdapter.notifyItemRemoved(i);
//                            break;
//                        }
//                    }
                    mTimeLineStatusAdapter.SyncDelSingle();
                    break;
                case ACTIONs.actionStatusDleteUpdate:
                    loadStatus(true);
                    break;
            }
        }
    };

    // 同步动态
    private void doSyncStatus(boolean isAdd, int statusID) {
        if (isAdd) {
            if (statusID == YNSingleton.getInstance().getCurStatus().getEid()) {
                mTimeLineStatusAdapter.addItemsFromTopOne(YNSingleton.getInstance().getCurStatus());
                mRecyclerView.scrollToPosition(0);
            }
        } else {
            mTimeLineStatusAdapter.removeOne(statusID);
        }
    }

    private void registerBroadcastReceiver() {
        IntentFilter myIntentFilter = new IntentFilter();
        myIntentFilter.addAction(ACTIONs.actionStatusUpdate);
        myIntentFilter.addAction(ACTIONs.actionStatusDleteUpdate);
        myIntentFilter.addAction(ACTIONs.actionStatusUpdateRefresh);
        myIntentFilter.addAction(ACTIONs.actionOfficialStatusUpdate);
        myIntentFilter.addAction(ACTIONs.actionComment);
        myIntentFilter.addAction(ACTIONs.actionLike);
        myIntentFilter.addAction(ACTIONs.actionStatus);
        myIntentFilter.addAction(ACTIONs.actionSinglePhoto);
        myIntentFilter.addAction(ACTIONs.timeLineLead);
        myIntentFilter.addAction(ACTIONs.modifyStatus);
        myIntentFilter.addAction(ACTIONs.actionUpdateFristAlbum);
        myIntentFilter.addAction(ACTIONs.actionUpdateEmptyAlbum);
        myIntentFilter.addAction(ACTIONs.actionGroupQuit);
        myIntentFilter.addAction("doClickFristShare");
        myIntentFilter.addAction("doReward");
        registerReceiver(mStatusBroadcastReceiver, myIntentFilter);
    }


    private void noticeServiceInit() {
        isBottom = false;
        LinkedHashMap<String, String> mParam = new LinkedHashMap<>();
        mParam.put(CommonConstants.YNS_USER_ID, String.valueOf(application.getCurID()));
        mParam.put(CommonConstants.YNS_GROUP_ID, String.valueOf(curAlbum.getGroupid()));
        mParam.put(CommonConstants.YNS_EID, String.valueOf(0));
        mParam.put(CommonConstants.YNS_TYPE, "initialize");
        StringRequest req = new StringRequest("https://api.zhuiyinanian.com/YinianProject/event/ShowTimeAxis")
                .setMethod(HttpMethods.Post)
                .setParamMap(mParam)
                .setHttpListener(new HttpListener<String>(true, false, true) {
                    @Override
                    public void onSuccess(String s, Response<String> response) {
                        Log.i("xjs", "ffff+ssss====>" + s);
                        YNStatusResponse resAlbumStatus = gson.fromJson(s, YNStatusResponse.class);
                        if (resAlbumStatus != null && ReqUtils.isSuccess(resAlbumStatus.getCode())) {
                            updateView(true, resAlbumStatus.getData());
                        }
                    }

                    @Override
                    public void onFailure(HttpException e, Response<String> response) {
//                        showToast(CommonConstants.YN_NET_LINK);
                    }
                });
        liteHttp.executeAsync(req);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        unregisterReceiver(mStatusBroadcastReceiver);
        members_recycler_horizontal.stop();
        Glide.get(this).clearMemory();
        System.gc();
    }

    private void noticeRewardsServiceInit() {
        LinkedHashMap<String, String> mParam = new LinkedHashMap<>();
        mParam.put(CommonConstants.YNS_GROUP_ID, String.valueOf(curAlbum.getGroupid()));
        StringRequest req = new StringRequest("https://api.zhuiyinanian.com/YinianProject/activity/ShowRewardBroadcast")
                .setMethod(HttpMethods.Post)
                .setParamMap(mParam)
                .setHttpListener(new HttpListener<String>(true, false, true) {
                    @Override
                    public void onSuccess(String s, Response<String> response) {
                        YNRewardResponse rewardResponse = gson.fromJson(s, YNRewardResponse.class);
                        if (rewardResponse != null && ReqUtils.isSuccess(rewardResponse.getCode())) {
                            mRewardDatas.clear();
                            mRewardDatas.addAll(rewardResponse.getData());
                            mAdapter = new MembersHorizontalTopAdapter(TimeLineStatusFristActivity.this, mRewardDatas);
                            members_recycler_horizontal.setAdapter(mAdapter);
                            mAdapter.notifyDataSetChanged();
                            members_recycler_horizontal.start();
                        }
                    }

                    @Override
                    public void onFailure(HttpException e, Response<String> response) {
//                        showToast(CommonConstants.YN_NET_LINK);
                    }
                });
        liteHttp.executeAsync(req);
    }

    private void noticePaihangServiceInit() {
        LinkedHashMap<String, String> mParam = new LinkedHashMap<>();
        mParam.put(CommonConstants.YNS_USER_ID, String.valueOf(application.getCurID()));
        mParam.put(CommonConstants.YNS_GROUP_ID, String.valueOf(curAlbum.getGroupid()));
        StringRequest req = new StringRequest("https://api.zhuiyinanian.com/YinianProject/activity/ShowChart")
                .setMethod(HttpMethods.Post)
                .setParamMap(mParam)
                .setHttpListener(new HttpListener<String>(true, false, true) {
                    @Override
                    public void onSuccess(String s, Response<String> response) {
                        try {
                            JSONObject jsonObject = new JSONObject(s);
                            if (jsonObject.optInt("code") == 0) {
                                int num = jsonObject.optJSONArray("data").optJSONObject(0).optJSONArray("personalChart").optJSONObject(0).optInt("num");
                                Iterator iter = rewardtips.entrySet().iterator();
                                while (iter.hasNext()) {
                                    Map.Entry entry = (Map.Entry) iter.next();
                                    int key = (Integer) entry.getKey();
                                    if (key == num) {
                                        if (!SpUtils.getBoolean(TimeLineStatusFristActivity.this, String.valueOf(application.getCurID()) + ":" + key)) {
                                            String tt = "恭喜你！收获" + key + "个赞，获得了" + entry.getValue() + "添加小忆（微信号：yinianniubi）领取。";
                                            showRewardTip(tt);
                                            SpUtils.put(TimeLineStatusFristActivity.this, String.valueOf(application.getCurID()) + ":" + key, true);
                                        }
                                    }
                                }
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    public void onFailure(HttpException e, Response<String> response) {
//                        showToast(CommonConstants.YN_NET_LINK);
                    }
                });
        liteHttp.executeAsync(req);
    }

    private void showRewardTip(String contentstr) {
        android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(this);
        builder.setCancelable(false);
        final android.support.v7.app.AlertDialog dlg = builder.create();
        dlg.show();
        Window window = dlg.getWindow();
        window.setContentView(R.layout.pub_tip_dialog);
        window.setBackgroundDrawableResource(R.color.transparent);
        WindowManager.LayoutParams layout = dlg.getWindow().getAttributes();
        layout.width = DisplayUtils.getScreenWidthPixels(this) - DisplayUtils.dp2px(this, 35 * 2);
        dlg.getWindow().setAttributes(layout);
        TextView tt = (TextView) window.findViewById(R.id.pp_title);
        tt.setText("提示");
        TextView content = (TextView) window.findViewById(R.id.pp_content);
        content.setText(contentstr);
        final TextView ok = (TextView) window.findViewById(R.id.btn_ok);
        ok.setText("知道了");
        ok.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                dlg.cancel();
            }
        });
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        switch (id) {
            case R.id.top_back:
            case R.id.top_back_time:
                finish();
                break;
            case R.id.peoplespace_search:
                startActivity(new Intent(TimeLineStatusFristActivity.this, TimeLineStatusFristSearchActivity.class).putExtra("StatusFrist", curAlbum));
                break;
            case R.id.btn_space_huodong:
                startActivity(new Intent(TimeLineStatusFristActivity.this, TimeLineStatusFristHuoDongActivity.class).putExtra("StatusFrist", curAlbum));
                break;
            case R.id.btn_space_paihangbang:
                startActivity(new Intent(TimeLineStatusFristActivity.this, TimeLineStatusFristPaiHangActivity.class).putExtra("StatusFrist", curAlbum));
                break;
            case R.id.btn_middle_selector:
                OpenButtons();
                break;
            case R.id.buttons_cover:
            case R.id.btn_middle_selector_copy:
                CloseButtons();
                break;
            case R.id.tv_image:
                ImageLocalSelectActivity.IsSmall = false;
                Intent intent = new Intent(TimeLineStatusFristActivity.this, ImageLocalSelectActivity.class);
                intent.putExtra("mainImage", true);
                intent.putExtra("fromfrist", true);
                intent.putExtra("gid", curAlbum.getGroupid());
                startActivity(intent);
                CloseButtons();
                break;
            case R.id.tv_pailide:
                ImageLocalSelectActivity.IsSmall = false;
                Intent pintent = new Intent(TimeLineStatusFristActivity.this, CameraActivity.class);
                pintent.putExtra("fromfrist", true);
                pintent.putExtra("gid", curAlbum.getGroupid());
                startActivity(pintent);
                CloseButtons();
                break;

        }

    }

    private void doReward(int userid, final int type) {
        LinkedHashMap<String, String> mParam = new LinkedHashMap<>();
        mParam.put(CommonConstants.YNS_USER_ID, String.valueOf(userid));
        mParam.put(CommonConstants.YNS_TYPE, String.valueOf(type));
        mParam.put(CommonConstants.YNS_GROUP_ID, String.valueOf(curAlbum.getGroupid()));
        StringRequest req = new StringRequest("https://api.zhuiyinanian.com/YinianProject/activity/AddRewardInfo")
                .setMethod(HttpMethods.Post).setParamMap(mParam)
                .setHttpListener(new HttpListener<String>() {
                    @Override
                    public void onSuccess(String s, Response<String> response) {
                        Log.i("xjs", "doReward==>" + s);
                        try {
                            JSONObject jsonObject = new JSONObject(s.toString());
                            if (jsonObject.optString("msg").equals("success") && jsonObject.optInt("code") == 0) {
//                                Toast.makeText(context, "成功", Toast.LENGTH_SHORT).show();
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    public void onFailure(HttpException e, Response<String> response) {
//                        Toast.makeText(mContext, CommonConstants.YN_NET_LINK, Toast.LENGTH_SHORT).show();
                    }
                });
        liteHttp.executeAsync(req);
    }

}
